package com.dingreading.cloud.admin.service.impl;

import com.dingreading.cloud.admin.entity.GoodsImg;
import com.dingreading.cloud.admin.entity.table.GoodsImgTableDef;
import com.dingreading.cloud.admin.mapper.GoodsImgMapper;
import com.dingreading.cloud.admin.service.GoodsImgService;
import com.mybatisflex.core.query.QueryCondition;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务层实现。
 *
 * @author Administrator
 * @since 2023-11-22
 */
@Service
public class GoodsImgServiceImpl extends BaseServiceImpl<GoodsImgMapper, GoodsImg, GoodsImgTableDef> implements GoodsImgService {

    @Override
    protected GoodsImgTableDef getTable() {
        return GoodsImgTableDef.goodsImg;
    }

    @Override
    public void deleteByGoodsIdAndIds(Long goodsId, List<Long> ids) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.goodsId.eq(goodsId));
        if (CollectionUtils.isNotEmpty(ids))
            condition.and(table.id.in(ids));
        getMapper().deleteByCondition(condition);
    }

    @Override
    public void deleteByGoodsIdAndIdsNot(Long goodsId, List<Long> ids) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.goodsId.eq(goodsId));
        if (CollectionUtils.isNotEmpty(ids))
            condition.and(table.id.notIn(ids));
        getMapper().deleteByCondition(condition);
    }

    @Override
    public List<GoodsImg> getByGoodsId(Long goodsId) {
        return getMapper().selectListByCondition(table.goodsId.eq(goodsId));
    }

    @Override
    public List<GoodsImg> getByGoodsIdAndIdsNot(Long goodsId, List<Long> ids) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.goodsId.eq(goodsId));
        if (CollectionUtils.isNotEmpty(ids))
            condition.and(table.id.notIn(ids));
        return getMapper().selectListByCondition(condition);
    }

}
